import * as actionTypes from './constants'


import { getTopBanners,
         getHotRecommends,
         getNewAlbum,
         getTopList,
         getSettleData,
         getHotAnchorData
        } from '@/services/api/recommend'
// 轮播图
const changeTopBannerAction = (res) => ({
  type: actionTypes.CHANGE_TOP_BANNERS,
  topBanners: res.banners
})
// 热门推荐
const changeHotRecommendAction = (res) => ({
  type: actionTypes.CHANGE_HOT_RECOMMEND,
  hotRecommends: res.result
})
// 新碟上架
const changeNewAlbumAction = (res) => ({
  type: actionTypes.CHANGE_NEW_ALBUM,
  newAlbums: res.weekData
})
// 榜单-飙升榜
const changeUpRankingAction = (res) => ({
  type: actionTypes.CHANGE_UP_RANKING,
  upRanking: res.playlist
})
// 榜单-新歌榜
const changeNewRankingAction = (res) => ({
  type: actionTypes.CHANGE_NEW_RANKING,
  newRanking: res.playlist
}) 
// 榜单-原创榜
const changeOriginRankingAction = (res) => ({
  type: actionTypes.CHANGE_ORIGIN_RANKING,
  originRanking: res.playlist
})
// 入驻歌手
const changeSettleSingerAction = (res) => ({
  type: actionTypes.CHANGE_SETTLE_SINGER,
  settleSingers: res.list.artists
})
// 热门主播
const changeHotAnchorAction = (res) => ({
  type: actionTypes.CHANGE_HOT_ANCHOR,
  hotAnchors: res.data.list
})
export const getTopBannerAction = () => {
  return dispatch => {
    getTopBanners().then(res => {
      dispatch(changeTopBannerAction(res))
    })
  }
}

export const getHotRecommendAction = (limit) => {
  return (dispatch) => {
    getHotRecommends(limit).then(res => {
      dispatch(changeHotRecommendAction(res))
    })
  }
}

export const getNewAlbumAction  = (limit) => {
  return dispatch => {
    getNewAlbum(limit).then(res => {
      dispatch(changeNewAlbumAction(res))
    })
  }
}

export const getTopListAction = (id) =>{
  return dispatch => {
    switch(id) {
      case 19723756:
        getTopList(id).then(res =>{
          dispatch(changeUpRankingAction(res))
        })
        break;
      case 3779629:
        getTopList(id).then( res => {
          dispatch(changeNewRankingAction(res))
        })
        break;
      case 2884035:
        getTopList(id).then( res => {
          dispatch(changeOriginRankingAction(res))
        })
        break;
      default:
    }
  }
}

export const getSettleSingerAction = () =>{
  return dispatch => {
    getSettleData().then(res => {
      dispatch(changeSettleSingerAction(res))
    })
  }
}

export const getHotAnchorAction = (limit) =>{
  return dispatch => {
    getHotAnchorData(limit).then(res => {
      dispatch(changeHotAnchorAction(res))
    })
  }
}